package com.hr.GC;

/**
 * @program: leetcode
 * @description: GC测试  -XX:PrintGCDetails
 * @author: HuRan QQ1345122890
 * @create: 2021-03-27 10:48
 */
public class LocalVGCTtest {
    //不会GC
    public void test01() {
        byte[] buffer = new byte[10 * 1024 * 1024];
        System.gc();
    }

    //会GC
    public void test02() {
        byte[] buffer = new byte[10 * 1024 * 1024];
        buffer = null;
        System.gc();
    }

    //不会GC C 查看字节码发现  局部变量表中索引为1
    public void test03() {
        {
            byte[] buffer = new byte[10 * 1024 * 1024];

        }
        System.gc();
    }

    //会GC 查看字节码发现  局部变量表中索引为1 的位置value占用了buffer
    public void test04() {
        {
            byte[] buffer = new byte[10 * 1024 * 1024];
        }
        //buffer超出了作用于 value会占用buffer的槽
        int value = 10;
        System.gc();
    }

    //会GC
    public void test05() {
        test01();
        System.gc();
    }

    public static void main(String[] args) {

    }

}